/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-09-02 14:38:15
 * @LastEditors: Du Weixing duweixing@sgsimulation.com
 * @LastEditTime: 2024-12-06 19:56:33
 * @FilePath: \SGFEM\DataStructure\FEM\Property\src\PBEAMLData.cpp
 */

#include "DataStructure/Input/Property/PBEAMLData.h"

#include <cstddef>
#include <cstring>
#include <string>

#include "DataStructure/Common/Validation.h"
#include "DataStructure/Input/Property/BeamSectionStandardTypes.h"

using namespace SG::DataStructure::FEM;

SG::DataStructure::FEM::BeamSectionStandardTypes PBEAMLData::GetBeamSectionStandardTypes ()
{
    std::string const str (m_type);
    if (str == "ROD")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_ROD;
    }
    if (str == "BAR")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BAR;
    }
    if (str == "TUBE")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_TUBE;
    }
    if (str == "TUBE2")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_TUBE2;
    }
    if (str == "BOX")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BOX;
    }
    if (str == "BOX1")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BOX1;
    }
    if (str == "DBOX")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BOX;
    }
    if (str == "I")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_I;
    }
    if (str == "I1")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_I1;
    }
    if (str == "H")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_H;
    }
    if (str.compare ("L") == 0)
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_L;
    }
    if (str == "CHAN")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN;
    }
    if (str == "CHAN1")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN1;
    }
    if (str == "CHAN2")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN2;
    }
    if (str == "T")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T;
    }
    if (str == "T1")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T1;
    }
    if (str == "T2")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T2;
    }
    if (str == "CROSS")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CROSS;
    }
    if (str == "Z")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_Z;
    }
    if (str == "HEXA")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HEXA;
    }
    if (str == "HAT")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HAT;
    }
    if (str == "HAT1")
    {
        return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HAT1;
    }

    return SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_UNKNOW;
};

void PBEAMLData::SetBeamSectionStandardTypes (SG::DataStructure::FEM::BeamSectionStandardTypes type)
{
    if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_ROD)
    {
        // m_type =  "ROD" ;
        std::strcpy (m_type, "ROD");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BAR)
    {
        std::strcpy (m_type, "BAR");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_TUBE)
    {
        std::strcpy (m_type, "TUBE");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_TUBE2)
    {
        std::strcpy (m_type, "TUBE2");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BOX)
    {
        std::strcpy (m_type, "BOX");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_BOX1)
    {
        std::strcpy (m_type, "BOX1");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_I)
    {
        std::strcpy (m_type, "I");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_I1)
    {
        std::strcpy (m_type, "I1");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_H)
    {
        std::strcpy (m_type, "H");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_L)
    {
        std::strcpy (m_type, "L");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN)
    {
        std::strcpy (m_type, "CHAN");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN1)
    {
        std::strcpy (m_type, "CHAN1");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CHAN2)
    {
        std::strcpy (m_type, "CHAN2");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T)
    {
        std::strcpy (m_type, "T");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T1)
    {
        std::strcpy (m_type, "T1");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_T2)
    {
        std::strcpy (m_type, "T2");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_CROSS)
    {
        std::strcpy (m_type, "CROSS");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_Z)
    {
        std::strcpy (m_type, "Z");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HEXA)
    {
        std::strcpy (m_type, "HEXA");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HAT)
    {
        std::strcpy (m_type, "HAT");
    }
    else if (type == SG::DataStructure::FEM::BeamSectionStandardTypes::BEAMSECTYPE_HAT1)
    {
        std::strcpy (m_type, "HAT1");
    }
};

void PBEAMLData::SetGroup (const char* str)
{
    std::strcpy (m_group, str);
}

std::string PBEAMLData::GetGroup ()
{
    std::string str (m_group);
    return str;
}

bool SG::DataStructure::FEM::operator== (const PBEAMLData& a, const PBEAMLData& b)
{
    if (a.m_mId != b.m_mId)
    {
        return false;
    }

    if (std::strncmp (a.m_group, b.m_group, 8) != 0)
    {
        return false;
    }

    if (std::strncmp (a.m_type, b.m_type, 8) != 0)
    {
        return false;
    }

    if (a.m_domainId != b.m_domainId)
    {
        return false;
    }

    if (a.m_section.size () != b.m_section.size ())
    {
        return false;
    }

    for (size_t i = 0; i < a.m_section.size (); ++i)
    {
        const auto& secA = a.m_section[i];
        const auto& secB = b.m_section[i];

        if (!SG::DataStructure::Common::isNear (secA.m_so, secB.m_so))
        {
            return false;
        }

        if (!SG::DataStructure::Common::isNear (secA.m_rdist, secB.m_rdist))
        {
            return false;
        }

        if (!SG::DataStructure::Common::isNear (secA.m_nsm, secB.m_nsm))
        {
            return false;
        }

        if (secA.m_dims.size () != secB.m_dims.size ())
        {
            return false;
        }

        for (size_t j = 0; j < secA.m_dims.size (); ++j)
        {
            if (!SG::DataStructure::Common::isNear (secA.m_dims[j], secB.m_dims[j]))
            {
                return false;
            }
        }
    }

    return true;
}